<template>
  <div class="home-center">
    <!-- 顶部大图改为轮播图 -->
    <div class="banner">
      <el-carousel height="400px" :interval="5000" arrow="always">
        <el-carousel-item v-for="(item, index) in carouselItems" :key="index">
          <div class="banner-content" :style="{ backgroundImage: `url(${item.image})` }">
            <div class="banner-text">
              <h1>{{ item.title }}</h1>
              <h2>{{ item.subtitle }}</h2>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <!-- 四个图标导航 -->
    <div class="nav-cards">
      <div class="nav-card" v-for="(item, index) in navItems" :key="index">
        <div class="icon-bg" :style="{ backgroundColor: item.bgColor }">
          <i :class="item.icon"></i>
        </div>
        <p>{{ item.title }}</p>
      </div>
    </div>

    <!-- 新闻和动态部分 -->
    <div class="news-container">
      <!-- 学院新闻 -->
      <div class="news-section">
        <div class="section-header">
          <div class="title">
            <i class="el-icon-news"></i>
            <span>学院新闻</span>
          </div>
          <a href="#" class="more">查看更多 >></a>
        </div>
        <div class="news-list">
          <div class="news-item" v-for="(news, index) in newsList" :key="index">
            <span class="news-title">{{ news.title }}</span>
            <span class="news-date">{{ news.date }}</span>
          </div>
        </div>
      </div>

      <!-- 行业动态 -->
      <div class="news-section">
        <div class="section-header">
          <div class="title">
            <i class="el-icon-data-line"></i>
            <span>行业动态</span>
          </div>
          <a href="#" class="more">查看更多 >></a>
        </div>
        <div class="news-list">
          <div class="news-item" v-for="(news, index) in industryNews" :key="index">
            <span class="news-title">{{ news.title }}</span>
            <span class="news-date">{{ news.date }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCarouselItems } from '@/api/home'
export default {
  name: 'HomeBanner',
  data() {
    return {
      carouselItems: [
        {
          title: '兰台档案研究院',
          subtitle: 'Lantai Archives Research Institute',
          image: 'https://picsum.photos/1920/400?random=1'
        },
        {
          title: '专业培训课程',
          subtitle: 'Professional Training Courses',
          image: 'https://picsum.photos/1920/400?random=2'
        },
        {
          title: '考证助力未来',
          subtitle: 'Certification for Future',
          image: 'https://picsum.photos/1920/400?random=3'
        }
      ],
      navItems: [
        {
          title: '消防设施操作员',
          icon: 'el-icon-warning-outline',
          bgColor: '#FF7B7B'
        },
        {
          title: '公务员考试',
          icon: 'el-icon-edit-outline',
          bgColor: '#7B9CFF'
        },
        {
          title: '新闻记者培训',
          icon: 'el-icon-document',
          bgColor: '#4CD9C9'
        },
        {
          title: '档案整理培训',
          icon: 'el-icon-folder-opened',
          bgColor: '#DEB887'
        }
      ],
      newsList: [
        { title: '【拓诚学院周年庆】里程千年，优秀学员分享过考经验', date: '2023-09-07' },
        { title: '10月重庆消防监控方向计划考试2428人，排名3000名以内...', date: '2023-09-07' },
        { title: '探究学员满分背后的秘密，另有两项你该知道的考试新变化', date: '2023-09-13' },
        { title: '忽视消防设施，无证上岗，重庆某公司被罚4.1万元', date: '2023-09-13' },
        { title: '9月新班开班，消防国考捷报不断，有学员不到三月顺利拿证', date: '2023-09-20' }
      ],
      industryNews: [
        { title: '12月重庆消防监控方向计划考试3332人，继保方向暂无考...', date: '2023-11-01' },
        { title: '【消防考生注意】中级消防设施操作员（监控方向）11月能...', date: '2023-10-16' }
      ]
    }
  },
  methods:{
    selectData(){
      getCarouselItems().then(res => {
        console.log(res)
      })
    }
  },
  mounted(){
    this.selectData()
  }
}
</script>

<style lang="scss" scoped>
.home-center {
  .banner {
    .el-carousel {
      .banner-content {
        height: 400px;
        background-size: cover;
        background-position: center;
        position: relative;
        
        .banner-text {
          position: absolute;
          left: 120px;
          top: 100px;
          z-index: 1;
          
          h1 {
            font-size: 42px;
            color: #fff;
            margin-bottom: 15px;
            font-weight: bold;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
          }
          
          h2 {
            font-size: 24px;
            color: #fff;
            font-weight: normal;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
          }
        }
      }
    }
  }

  .nav-cards {
    width: 1200px;
    margin: -60px auto 0;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    position: relative;
    z-index: 2;

    .nav-card {
      width: 260px;
      height: 180px;
      background: #fff;
      border-radius: 10px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      transition: transform 0.3s;
      cursor: pointer;

      &:hover {
        transform: translateY(-10px);
      }

      .icon-bg {
        width: 80px;
        height: 80px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 15px;

        i {
          font-size: 36px;
          color: #fff;
        }
      }

      p {
        font-size: 16px;
        color: #333;
        margin: 0;
      }
    }
  }

  .news-container {
    width: 1200px;
    margin: 40px auto;
    display: flex;
    gap: 20px;

    .news-section {
      flex: 1;
      background: #fff;
      border-radius: 10px;
      padding: 20px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
      transition: all 0.3s ease;

      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
      }

      .section-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 15px;
        border-bottom: 1px solid #eee;
        margin-bottom: 15px;

        .title {
          display: flex;
          align-items: center;
          gap: 10px;
          font-size: 18px;
          font-weight: bold;
          color: #333;
          position: relative;
          padding-left: 10px;
          
          &::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 20px;
            background-color: #409EFF;
          }

          i {
            font-size: 20px;
          }
        }

        .more {
          color: #999;
          font-size: 14px;
          text-decoration: none;
          
          &:hover {
            color: #409EFF;
          }
        }
      }

      .news-list {
        .news-item {
          display: flex;
          justify-content: space-between;
          padding: 12px 0;
          border-bottom: 1px dashed #eee;

          &:last-child {
            border-bottom: none;
          }

          .news-title {
            flex: 1;
            font-size: 14px;
            color: #666;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            cursor: pointer;

            &:hover {
              color: #409EFF;
            }
          }

          .news-date {
            color: #999;
            font-size: 14px;
            margin-left: 20px;
          }
        }
      }
    }
  }
}

// 自定义轮播图箭头样式
.el-carousel__arrow {
  background-color: rgba(255, 255, 255, 0.7);
  
  &:hover {
    background-color: rgba(255, 255, 255, 0.9);
  }
  
  i {
    color: #333;
  }
}
</style>